package com.cqupt.scanning.system.file.controller;

import com.cqupt.scanning.system.file.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import java.io.IOException;

/**
 * @Data: 2021/7/6 20:10
 * @Author: 宋宝梁
 */
@RestController
@RequestMapping("/scanning")
public class FileController {

    private FileService fileService;

    @Autowired
    public FileController(FileService fileService) {
        this.fileService = fileService;
    }

    /**
     * 1.上传足底扫描压缩文件 2.解析文件数据 3.数据入库 4.报告生成
     * @param file
     * @param request
     * @param response
     * @throws IOException
     */
    @PostMapping("/uploadFile/uploadFootFile")
    @PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.uploadFootFile')")
    public void uploadFootFile(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
        fileService.handleFootFile(file, request, response);
    }

    /**
     * 下载当前足底扫描病人步态分析报告
     * @param id
     * @param response
     */
    @GetMapping("/downloadFile/downloadGaitPdf/{id}")
    @PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.downloadGaitPdf')")
    public void downloadGaitPdf(@PathVariable Integer id, HttpServletResponse response) {
        fileService.downloadGaitPdf(id, response);
    }

    /**
     * 下载当前足底扫描病人平衡分析报告
     * @param id
     * @param response
     */
    @GetMapping("/downloadFile/downloadBalancePdf/{id}")
    @PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.downloadBalancePdf')")
    public void downloadBalancePdf(@PathVariable Integer id, HttpServletResponse response) {
        fileService.downloadBalancePdf(id, response);
    }

    /**
     * 1.上传三维扫描压缩文件 2.解析文件数据 3.数据入库 4.报告生成
     * @param file
     * @param request
     * @param response
     * @throws IOException
     */
    @PostMapping("/uploadFile/uploadThreeFile")
    @PreAuthorize("hasAnyAuthority('三维扫描', '3Dscanning.uploadThreeFile')")
    public void uploadThreeFile(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
        fileService.handleThreeFile(file, request, response);
    }

    /**
     * 下载当前三维扫描病人报告
     * @param id
     * @param response
     */
    @GetMapping("/downloadFile/downloadThreePdf/{id}")
//    @PreAuthorize("hasAnyAuthority('三维扫描', '3Dscanning.downloadThreePdf')")
    public void downloadThreeFile(@PathVariable Integer id, HttpServletResponse response) {
        fileService.downloadThreeFile(id, response);
    }

    /**
     * 下载当前足底扫描病人压缩文件（含所有文件）
     * @param id
     * @param response
     */
    @GetMapping("/downloadFile/footZipFile/{id}")
    @PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.footZipFile')")
    public void downloadFootZipFile(@PathVariable Integer id, HttpServletResponse response) {
        fileService.downloadFootZipFile(id, response);
    }

    /**
     * 下载当前三维扫描病人压缩文件（含所有文件）
     * @param id
     * @param response
     */
    @GetMapping("/downloadFile/threeZipFile/{id}")
    @PreAuthorize("hasAnyAuthority('三维扫描', '3Dscanning.threeZipFile')")
    public void downloadThreeZipFile(@PathVariable Integer id, HttpServletResponse response) {
        fileService.downloadThreeZipFile(id, response);
    }

    /**
     * 下载当前足底扫描病人的左脚csv文件
     * @param id
     * @param response
     */
    @GetMapping("/downloadFile/leftFootCsv/{id}")
    @PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.leftFootCsv')")
    public void downloadLeftCsvFile(@PathVariable Integer id, HttpServletResponse response) {
        fileService.downloadLeftCsvFile(id, response);
    }

    /**
     * 下载当前足底扫描病人的右脚csv文件
     * @param id
     * @param response
     */
    @GetMapping("/downloadFile/rightFootCsv/{id}")
    @PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.rightFootCsv')")
    public void downloadRightCsvFile(@PathVariable Integer id, HttpServletResponse response) {
        fileService.downloadRightCsvFile(id, response);
    }

    /**
     * 批量下载步态pdf报告
     * return
     */
    @GetMapping("/downloadFile/footZipFile/batchFootZipFile")
    //@PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.batchFootZipFile')")
    public void downloadBatchFootZipFile(
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "age_lower",required = false) String ageLower,
            @RequestParam(value = "age_upper",required = false) String ageUpper,
            @RequestParam(value = "doctor",required = false) String doctor,
            @RequestParam(value = "height_lower",required = false) String heightLower,
            @RequestParam(value = "height_upper",required = false) String heightUpper,
            @RequestParam(value = "measureMode",required = false) String measureMode,
            @RequestParam(value = "sex",required = false) String sex,
            @RequestParam(value = "weight_lower",required = false) String weightLower,
            @RequestParam(value = "weight_upper",required = false) String weightUpper,
            @RequestParam(value = "beginTime",required = false) String beginTime,
            @RequestParam(value = "endTime",required = false) String endTime,
            @RequestParam(value = "phone",required = false) String phone,
            HttpServletRequest request,HttpServletResponse response
    ) throws IOException {

        fileService.downloadBatchFootZipFile(name,ageLower,ageUpper,doctor,heightLower,heightUpper,measureMode,sex,weightLower,weightUpper,beginTime,endTime,phone,request,response);
    }

    /**
     * 批量下载平衡pdf报告
     * return
     */
    @GetMapping("/downloadFile/footZipFile/batchBalanceZipFile")
    // @PreAuthorize("hasAnyAuthority('步态分析', 'plantarScanning.batchBalanceZipFile')")
    public void downloadBatchBalanceZipFile(
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "age_lower",required = false) String ageLower,
            @RequestParam(value = "age_upper",required = false) String ageUpper,
            @RequestParam(value = "doctor",required = false) String doctor,
            @RequestParam(value = "height_lower",required = false) String heightLower,
            @RequestParam(value = "height_upper",required = false) String heightUpper,
            @RequestParam(value = "measureMode",required = false) String measureMode,
            @RequestParam(value = "sex",required = false) String sex,
            @RequestParam(value = "weight_lower",required = false) String weightLower,
            @RequestParam(value = "weight_upper",required = false) String weightUpper,
            @RequestParam(value = "beginTime",required = false) String beginTime,
            @RequestParam(value = "endTime",required = false) String endTime,
            @RequestParam(value = "phone",required = false) String phone,
            HttpServletRequest request,HttpServletResponse response
    ) throws IOException {
        fileService.downloadBatchBalanceZipFile(name,ageLower,ageUpper,doctor,heightLower,heightUpper,measureMode,sex,weightLower,weightUpper,beginTime,endTime,phone,request,response);
    }



    /**
     * 批量下载三维扫描报告
     * return
     */
    @GetMapping("/downloadFile/threeZipFile/batchThreeZipFile")
  //  @PreAuthorize("hasAnyAuthority('三维扫描', '3Dscanning.batchThreeZipFile')")
    public void downloadBatchThreeZipFile(
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "age_lower",required = false) String ageLower,
            @RequestParam(value = "age_upper",required = false) String ageUpper,
            @RequestParam(value = "height_lower",required = false) String heightLower,
            @RequestParam(value = "height_upper",required = false) String heightUpper,
            @RequestParam(value = "sex",required = false) String sex,
            @RequestParam(value = "weight_lower",required = false) String weightLower,
            @RequestParam(value = "weight_upper",required = false) String weightUpper,
            @RequestParam(value = "beginTime",required = false) String beginTime,
            @RequestParam(value = "endTime",required = false) String endTime,
            @RequestParam(value = "phone",required = false) String phone,
            HttpServletRequest request,HttpServletResponse response
    ) throws IOException {

        fileService.downloadBatchThreeZipFile(name,ageLower,ageUpper,heightLower,heightUpper,sex,weightLower,weightUpper,beginTime,endTime,phone,request,response);
    }

    /**
     * 批量下载步态分析源文件压缩包
     * @param beginTime
     * @param  endTime
     * return
    * */
    @GetMapping("/downloadFile/footZipFile/downloadBatchOriginalFootZipFile")
    public void downloadBatchOriginalFootZipFile(
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "age_lower",required = false) String ageLower,
            @RequestParam(value = "age_upper",required = false) String ageUpper,
            @RequestParam(value = "doctor",required = false) String doctor,
            @RequestParam(value = "height_lower",required = false) String heightLower,
            @RequestParam(value = "height_upper",required = false) String heightUpper,
            @RequestParam(value = "measureMode",required = false) String measureMode,
            @RequestParam(value = "sex",required = false) String sex,
            @RequestParam(value = "weight_lower",required = false) String weightLower,
            @RequestParam(value = "weight_upper",required = false) String weightUpper,
            @RequestParam(value = "orgName",required = false) String orgName,
            @RequestParam(value = "beginTime",required = false) String beginTime,
            @RequestParam(value = "endTime",required = false) String endTime,
            @RequestParam(value = "username",required = false) String userName,
            @RequestParam(value = "phone",required = false) String phone,
    HttpServletRequest request,HttpServletResponse response
    ) throws IOException {
        fileService.downloadBatchOriginalFootZipFile(name, ageLower, ageUpper, doctor, heightLower, heightUpper, measureMode, sex, weightLower, weightUpper, beginTime, endTime,userName,phone,orgName, request, response);
    }

    /**
     * 批量下载三维扫描分析源文件压缩包
     * @param beginTime
     * @param  endTime
     * return
     * */
    @GetMapping("/downloadFile/threeZipFile/downloadBatchOriginalThreeZipFile")
    public void downloadBatchOriginalThreeZipFile(
            @RequestParam(value = "username",required = false) String userName,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "sex",required = false) String sex,
            @RequestParam(value = "devNum",required = false) String devNum,
            @RequestParam(value = "business_name",required = false) String businessName,
            @RequestParam(value = "address",required = false) String address,
            @RequestParam(value = "city_province",required = false) String cityProvince,
            @RequestParam(value = "country",required = false) String country,
            @RequestParam(value = "phone",required = false) String phone,
            @RequestParam(value = "fax",required = false) String fax,
            @RequestParam(value = "age",required = false) String age,
            @RequestParam(value = "age_lower",required = false) String ageLower,
            @RequestParam(value = "age_upper",required = false) String ageUpper,
            @RequestParam(value = "height_lower",required = false) String heightLower,
            @RequestParam(value = "height_upper",required = false) String heightUpper,
            @RequestParam(value = "weight_lower",required = false) String weightLower,
            @RequestParam(value = "weight_upper",required = false) String weightUpper,
            @RequestParam(value = "weight_bearing_lower",required = false) String weightBearingLower,
            @RequestParam(value = "weight_bearing_upper",required = false) String weightBearingUpper,
            @RequestParam(value = "dress_shoe",required = false) String dressShoe,
            @RequestParam(value = "athletic_shoe",required = false) String athleticShoe,
            @RequestParam(value = "casual_shoe",required = false) String casualShoe,
            @RequestParam(value = "heels",required = false) String heels,
            @RequestParam(value = "beginTime",required = false) String beginTime,
            @RequestParam(value = "endTime",required = false) String endTime,

            @RequestParam(value = "orgName",required = false) String orgName,
            @RequestParam(value = "doctor",required = false) String doctor,
            @RequestParam(value = "measureMode",required = false) String measureMode,
            HttpServletRequest request,HttpServletResponse response
    ) throws IOException {
        fileService.downloadBatchOriginalThreeZipFile(name, ageLower, ageUpper, doctor, heightLower, heightUpper, measureMode, sex, weightLower, weightUpper, beginTime, endTime,userName,phone,orgName,businessName,address,cityProvince,country,fax,
                weightBearingLower, weightBearingUpper,dressShoe,athleticShoe,casualShoe,heels,age, request, response);
    }


    /**
     * 1.上传三维扫描压缩文件 2.解析文件数据 3.数据入库 4.报告生成
     * @param file
     * @param request
     * @param response
     * @throws IOException
     */
    @PostMapping("/uploadFile/uploadModFile")
//    @PreAuthorize("hasAnyAuthority('ModBus数据采集', 'plantarScanning.uploadModFile')")
    public void uploadModFile(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
        fileService.handleModFile(file, request, response);
    }
}

